import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import moment from 'moment';
import { modeFromSimple } from '/@/api/backs/workFlow/form';
import { DICT_TYPE, getDictDatas } from '/@/utils/dict';

export const columns: BasicColumn[] = [
  {
    title: '流程名称',
    dataIndex: 'name',
  },
  {
    title: '流程标识',
    dataIndex: 'key',
  },
  {
    title: '流程描述',
    dataIndex: 'description',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 100,
    customRender: ({ record }) => {
      const time = record.createTime;
      return time ? moment(time).format('YYYY-MM-DD') : '-';
    },
  },
  {
    title: '最新部署的流程定义',
    dataIndex: 'processDefinition',
    sorter: true,
    children: [
      {
        title: '流程版本',
        dataIndex: 'processDefinition.version',
        width: 80,
        customRender: ({ record }) => {
          const content = record.processDefinition ? 'V' + record.processDefinition.version : null;
          return content;
        },
      },

      {
        title: '激活状态',
        dataIndex: 'processDefinition.suspensionState',
        width: 120,
        slots: { customRender: 'swicth' },
      },
      {
        title: '部署',
        dataIndex: 'processDefinition.deploymentTime',
        width: 120,
        customRender: ({ record }) => {
          const time = record.processDefinition ? record.processDefinition.deploymentTime : null;
          return time ? moment(time).format('YYYY-MM-DD') : '-';
        },
      },
      {
        title: '发布状态',
        dataIndex: 'status',
        width: 80,
        slots: { customRender: 'status' },
      },
    ],
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '流程名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    field: 'key',
    label: '流程标识',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  // {
  //   field: 'category',
  //   label: '流程分类',
  //   component: 'ApiSelect',
  //   colProps: { span: 8 },
  //   componentProps: {
  //     api: getModelList,
  //     labelField: 'label',
  //     valueField: 'value',
  //     placeholder: '请选择流程分类',
  //     params: {
  //       dictType: 'bpm_model_category',
  //     },
  //   },
  // },
];
const isShow = (type: string) => type === 'edit';
//编辑
export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '流程名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入流程名称',
    },
  },
  {
    field: 'key',
    label: '流程标识',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入流程标识',
    },
  },
  {
    field: 'category',
    label: '流程分类',
    component: 'Select',
    required: true,
    componentProps: {
      options: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
      placeholder: '请选择流程分类',
    },
    ifShow: ({ values }) => isShow(values.propsType),
  },
  {
    field: 'description',
    label: '描述',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入流程描述',
    },
  },
  {
    field: 'formType',
    component: 'RadioGroup',
    label: '表单类型',
    componentProps: (values) => {
      return {
        options: [
          {
            label: '流程表单',
            value: 10,
          },
          {
            label: '业务表单',
            value: 20,
          },
        ],
        onchange: (e: any) => {},
      };
    },
    ifShow: ({ values }) => isShow(values.propsType),
  },
  {
    field: 'formId',
    label: '流程表单',
    component: 'ApiSelect',
    componentProps: {
      api: modeFromSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择流程表单',
      params: {
        dictType: 'bpm_model_category',
      },
    },
    ifShow: ({ values }) => isShow(values.propsType) && values.formType == 10,
  },
  {
    field: 'formCustomCreatePath',
    label: '表单提交路由',
    component: 'Input',
    componentProps: {
      placeholder: '请输入表单提交路由',
    },
    ifShow: ({ values }) => isShow(values.propsType) && values.formType == 20,
  },
  {
    field: 'formCustomViewPath',
    label: '表单查看路由',
    component: 'Input',
    componentProps: {
      placeholder: '请输入表单查看路由',
    },
    ifShow: ({ values }) => isShow(values.propsType) && values.formType == 20,
  },
];
